package org.urey.fmp.consumer.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.urey.fmp.commom.entity.EnumType;
import org.urey.fmp.commom.entity.User;
import org.urey.fmp.consumer.service.TestServiceFeign;

@RestController
public class TestController {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private TestServiceFeign testServiceFeign;

	@RequestMapping(value = "/test")
	public String test() throws Exception {
		User user1 = testServiceFeign.findOne(1L);
		logger.info("findOne user1:{}", user1);

		List<User> users = testServiceFeign.findList(Arrays.asList(1L, 2L));
		logger.info("findList users:{}", users);

		testServiceFeign.update(users.get(0), users.get(1));
		testServiceFeign.update(user1, new Date());
		testServiceFeign.update(users, new Date(), "urey");
		testServiceFeign.update(users, Arrays.asList(EnumType.E1, EnumType.E2, EnumType.E3), "urey", 1L);

		return "success";
	}

	@RequestMapping(value = "/test2")
	public String test2() throws Exception {
		Map<Long, User> users = testServiceFeign.findMap(Arrays.asList(1L, 2L));
		logger.info("findMap users:{}", users);
		return "success2";
	}

}
